package tags;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import model.Aluno;

import dao.AlunoDao;
import dao.AlunoDaoImpl;

public class TagEdicaoAluno extends SimpleTagSupport {

	public void doTag() throws JspException, IOException {
		AlunoDao aDao = new AlunoDaoImpl();
		List<Aluno> lista = new ArrayList<Aluno>();
		JspWriter out = getJspContext().getOut();
		try {
			lista = aDao.ConsultaListaAluno();
		} catch (SQLException e) {
			out.println(e.getMessage());
		}

		for (Aluno a : lista) {
			StringBuffer sb = new StringBuffer();
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(a.getRa());
			sb.append("</td>");
			sb.append("<td style=\"max-width: 450px; white-space: normal\">");
			sb.append(a.getNome());
			sb.append("</td>");
			sb.append("<td><input type=\"submit\" value=\"Alterar\" name=\"");
			sb.append(a.getRa());
			sb.append("\" />");
			sb.append("</td>");
			sb.append("<td><input type=\"submit\" value=\"Excluir\" name=\"");
			sb.append(a.getRa());
			sb.append("\" />");
			sb.append("</td>");
			sb.append("</tr>");
			out.println(sb.toString());
		}

	}
}
